<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>浏览器本地存储</title>
</head>
<body>
<h1>localStorage</h1>
<button onclick="saveData()">点我保存一个数据</button>
<button onclick="readData()">点我读取一个数据</button>
<button onclick="deleteData()">点我删除一个数据</button>
<button onclick="clearData()">点我清空所有</button>
<script>
    function saveData(){
        localStorage.setItem('msg','hello~你好啊，你看到我了嘛？')
        localStorage.setItem('msg2',666)
        const p={name:'张三',age:20}
        localStorage.setItem('person',JSON.stringify(p))
    }
    function readData(){
        console.log(localStorage.getItem('msg'));
        console.log(localStorage.getItem('msg2'));
        const p=localStorage.getItem('person')
        console.log(JSON.parse(p));
        console.log("-------------------------------------------")
    }
    function deleteData(){
        localStorage.removeItem('msg2')
    }
    function clearData(){
        localStorage.clear()
    }

</script>
</body>
</html>
